import { ErrorLocalCode } from "../defines/error.local.define";
import { IPlatform } from "../interface/platform.interface";
import { PlatformBase } from "./platform.base";

export class PlatformWx extends PlatformBase implements IPlatform{
    login(cb: Function): Promise<string | number | boolean> {
        return new Promise((resolve) => {
            let authCode = false;
            //@ts-ignore
            (wx as any).login({
                success(res:any) {
                    //发起网络请求
                    console.log('wx login back');
                    console.log(res);
                    authCode = res.code;
                    cb(authCode);
                    resolve(0);
                },
                fail() {
                    console.log('wx login back fail');
                    cb('');
                    resolve(ErrorLocalCode.PLATFORM_LOGIN_FAIED);
                },
            });
        });
    }
}